import { getPropByPath } from '@/utils'
import { formatTime } from '@/utils'
import dayjs from 'dayjs'
export const typeMap = {
  userType: {
    ADMIN: '超管',
    MERCHANT: '运营商',
    NORMAL_USER: '普通充电用户',
    SELF_OPERATION_ADMIN: '自运营超管',
    SELF_OPERATION_MERCHANT: '自运营代理商',
    STAFF: '员工',
    MERCHANT_PARTNER: '运营商分账人',
    APP_USER: '充电用户',
  },
  userStatus: {
    DELETED: '已删除',
    NORMAL: '正常',
    STOP: '停用',
  },
  gatewayType: {
    GATEWAY_2G: '2G网关',
    GATEWAY_4G: '4G网关',
    UNKNOWN: '未知类型',
  },
  deviceStatus: {
    ALL: '全部',
    ONLINE: '在线',
    CHARGING: '充电中',
    IDLE: '空闲',
    OFFLINE: '失联',
    BREAK_DOWN: '故障',
  },
  deviceType: {
    GATEWAY: '网关设备',
    NB_DEVICE: 'NB插座设备',
    SOCKET: '插座设备',
    SWIPCARD_DEVICE: '刷卡设备',
  },
  electricCardStatus: {
    USED: '使用中',
    FREEZE: '冻结中',
    UNBIND: '未绑定',
  },
  stationType: {
    MIX: '临充+套餐电站',
    // FREE: '免费电站',
    TEMPORARY: '临充电站',
    // MONTHLY: '套餐电站',
    NO_TYPE: '未知电站',
  },
  stationStatus: {
    NORMAL: '正常',
    CANCEL: '注销',
    DELETED: '删除',
    TOP: '停用',
  },
  payType: {
    PostPay: '后付款',
    PrePay: '预付款',
  },
  chargeOrderStatus: {
    ABNORMAL: '异常订单',
    ONGOING: '进行中',
    NOTCHECK: '未对账',
    CHECKED: '已对账',
    UNPAID: '未付款账单',
    PAID: '已付款账单',
    UNSETTLED: '待结算账单',
    SETTLED: '已结算账单',
    CHARGEEND: '充电结束订单',
  },
  targetUserType: {
    0: '全部',
    1: '充电用户',
    2: '商户',
  },
  identifyType: {
    1: '居民身份证',
    2: '临时居民身份证',
    3: '居民户口簿',
    4: '护照',
    5: '港澳居民来往内地通行证',
    6: '回乡证',
    7: '军人证',
    8: '武警身份证',
    9: '其他法定文件',
  },
  countryType: {
    CHN: '中华人民共和国',
    HKG: '香港',
    MAC: '澳门',
    CTN: '台湾',
  },
  merchantType: {
    '01': ' 企业',
    '02': ' 事业单位',
    '03': ' 民办非企业组织',
    '04': ' 社会团体',
    '05': ' 党政及国家机关',
    '06': ' 个人商户',
    '07': ' 个体工商户',
  },
  linkType: {
    LOSS_CONTACT_PG: 1, // 1:"失联端口",
    FAULT_PG: 2, // 2:"故障端口",
    ORDER_DETAIL: 3, // 3:"订单详情",
    ACTIVE_DETAIL: 4, // 4:"活动详情"
    TRANSACTION_DETAIL: 5,
  },
  messageType: {
    ORDER: '1', // 订单消息
    SET_TIMECARD: '2', // 套餐、时长卡消息
    WARNING: '3', // 告警消息
    XY_MESSAGE: '4', // 小易通知
    SHARE_ALARM: '5',
  },
  onlineAdvertStatus: {
    NOT_ONLINE: '未上线',
    ON_LINE: '上线中',
    OFF_LINE: '已下线',
    FINISH: '已结束',
  },
  advertType: {
    SCREENPIC: '插屏图',
    BANNERPIC: 'Banner图',
  },
  advertJumpType: {
    WEB: '网页',
    WEIXINMINI: '小程序',
  },
  advertFrequency: {
    ONEDAY: '每日只展示一次',
    SEVENDAY: '7日内只展示一次',
    EVERYTIME: '每进入首页及充电确认页面就展示',
  },
  advertLevel: {
    STAION: '按照电站',
    AREA: '按照区域',
  },
  orderStatus: {
    0: '充电中',
    7: '已完成',
  },
  payStatus: {
    //管理者给被管理者付款的状态
    UNPAID: '未支付',
    PAID: '已支付',
  },
  paytmentStatus: {
    UNPAID: '未支付',
    PAID: '未支付',
    FAILURE: '支付失败',
    REFUNDING: '退款中',
    REFUNDED: '已退款',
    REFUND_FAILURE: '退款失败',
  },
  paymentType: {
    WEIXIN_GZH: '微信公众号',
    WEIXIN_APP: '微信APP',
    ALIPAY_APP: '支付宝APP',
    UNIONPAY: '银联支付',
    WEIXIN_MP: '微信小程序',
    UNIONPAY_WEIXIN_APP: '银联-微信APP',
    UNIONPAY_WEIXIN_GZH: '银联-微信公众号',
    UNIONPAY_WEIXIN_MP: '银联-微信小程序',
    ORDINARY_WEIXIN_GZH: '普通商户-微信公众号',
    ORDINARY_WEIXIN_APP: '普通商户-微信APP',
    ORDINARY_WEIXIN_MP: '普通商户-微信小程序',
    ALIPAY_MP: '支付宝小程序',
    SMS_PAY: '话费支付',
  },
  paymentChannels: {
    '-1': '无支付权限',
    0: '微信公众号',
    1: '微信APP',
    2: '支付宝',
    3: '云闪付支付',
    4: '微信小程序',
    5: '银联-微信APP',
    6: '银联-微信公众号',
    7: '银联-微信小程序',
    8: '普通商户-微信公众号',
    9: '普通商户-微信APP',
    10: '普通商户-微信小程序',
    11: '支付宝小程序',
    13: '移动话费',
  },
  billType: {
    RECHARGEBILL: '充值订单',
    CONSUMBILL: '后付费充电订单',
    FREEBILL: '赠送订单',
    MONTHLYCARDBILL: '套餐订单',
    PREPAYMENT: '预付费充电订单',
    TIMECARDBILL: '时长卡订单',
    ENERGYBILL: '和能量订单',
  },
  applyType: {
    APPLY: '申请（代理）',
    COMPLETE: '完善（代理）',
    CREATE: '创建（运营商）',
  },
  applyStatus: {
    WAIT: '待审核',
    PASS: '通过',
    REFUSE: '未通过',
    CANCEL: '撤销',
  },
  chargeStatus: {
    UNKNOWN: '未知',
    PLUGOFF: '设备未检测到负载',
    FULLPOWER: '电量充满',
    OVERLOAD: '电流过载',
    TIMEOUT: '等待新周期超时',
    NORMALEND: '正常结束',
    HIGHTEMP: '过温保护',
    LOWPOWER: '起始功率不足',
    CHARGING: '充电中',
    OVERVOLTAGE: '线路电压过高',
    UNDERVOLTAGE: '线路电压过低',
    SHORTCIRCUIT: '设备发生短路',
    ELECTRIC_LEAKAGE: '漏电',
    RALAYSTUCK: '继电器故障',
    OUTLET_TIMEOUT: '插口充电时间过长',
    FLOAT_CHARGE_END: '平台判断结束',
    MANUALLY_STOP: '手动停止',
  },
  tokenType: {
    ANDROID: '安卓',
    IOS: 'IOS',
    GZH: '公众号',
    WECHAT_MINI_PROGRAM: '微信小程序',
    SWIPECARD: '刷卡',
    ALIPAY_MINI_PROGRAM: '支付宝小程序',
  },
  timeCardType: {
    1: '积分兑换',
    2: '购买',
    3: '赠送',
    4: '活动',
    5: '外部活动',
  },
  timeCardRefundTypeStatus: {
    1: '待退款',
    2: '已退款',
  },
  andEnergyType: {
    BUY_EN: '购买',
    PRESENT_EN: '赠送',
    VOUCHER_EN: '活动领取',
    EXTERNAL_EN: '外部活动',
    EXTERNAL_RIGHT_EN: '权益兑换',
  },
  andEnergyStatus: {
    REFUNDED: '已退款',
    REFUNDING: '退款中',
    REFUND_FAILURE: '退款失败',
  },
  actType: {
    0: '折扣活动',
    1: '优惠券活动',
    2: '时长卡活动',
    3: '和能量活动',
  },
  userRange: {
    0: '全部',
    1: '新用户',
    2: '30天活跃用户',
    3: '30天未活跃用户',
    4: '7天未活跃用户',
  },
  applyRange: {
    0: '全部',
    1: '充电订单',
    2: '时长卡订单',
    3: '和能量订单',
  },
  budgetType: {
    0: '定额优惠券',
    1: '随机金额优惠券',
  },
  obtainType: {
    0: '分享领取',
    1: '直接领取',
  },
  joinType: {
    0: '非自运营代理商',
    1: '自运营代理商',
  },
  externalTimeCardType: {
    0: '通用时长卡',
    1: '单电站时长卡',
    2: '部分电站通用时长卡',
  },
  actStatus: {
    0: '未开始',
    1: '上线',
    2: '下线',
  },
  pushFailMessage: {
    0: '不推送',
    1: '推送',
  },
  externalActivityType: {
    1: '时长卡',
    2: '和能量',
  },
  staPriceType: {
    DURATION: '阶梯功率计费',
    INTERVAL: '区间电价计费',
    FIXED: '固定价格计费',
  },

  radioOptions: (filteredKey = [], type) => {
    return Object.keys(typeMap[type])
      .filter((key) => !filteredKey.includes(key))
      .map((item) => {
        return {
          text: typeMap[type][item],
          label: parseInt(item).toString() === item ? parseInt(item) : item,
        }
      })
  },
  selectOptions: (filteredKey = [], type) => {
    return Object.keys(typeMap[type])
      .filter((key) => !filteredKey.includes(key))
      .map((item) => {
        return {
          label: typeMap[type][item],
          value: parseInt(item).toString() === item ? parseInt(item) : item,
        }
      })
  },
  repeatType: (val) => {
    if (val === 0) return '每天'
    const weekMap = {
      1: '一',
      2: '二',
      3: '三',
      4: '四',
      5: '五',
      6: '六',
      7: '天',
    }
    let newVal = JSON.stringify(val)
    let arr = newVal.split('').reverse()
    let repeatDay = ''
    for (let i = 1; i <= arr.length; i++) {
      if (+arr[i - 1] === 1) {
        repeatDay = repeatDay + '星期' + weekMap[i]
        if (arr.length !== i) {
          repeatDay = repeatDay + ','
        }
      }
    }
    return repeatDay
  },
  // createTime: (val, format = 'YYYY-MM-DD') => {
  //   if (!val) return
  //   return dayjs(val).format(format)
  // },
  formatTime: (val, format = 'YYYY-MM-DD HH:mm:ss') => {
    if (!val) return
    return dayjs(val).format(format)
  },
  commonTime: (val) => {
    if (!val) return
    return dayjs(val).format('YYYY-MM-DD HH:mm:ss')
  },
  activeDate: (val) => {
    if (!val) return
    return dayjs(val).format('YYYY-MM-DD HH:mm:ss')
  },
  startTime: (val) => {
    if (!val) return
    return dayjs(val).format('YYYY-MM-DD HH:mm:ss')
  },
  endTime: (val) => {
    if (!val) return
    return dayjs(val).format('YYYY-MM-DD HH:mm:ss')
  },
  actStartTime: (val) => {
    if (!val) return
    return dayjs(val).format('YYYY-MM-DD HH:mm:ss')
  },
  actEndTime: (val) => {
    if (!val) return
    return dayjs(val).format('YYYY-MM-DD HH:mm:ss')
  },
  actStart: (val) => {
    if (!val) return
    return dayjs(val).format('YYYY-MM-DD HH:mm:ss')
  },
  actEnd: (val) => {
    if (!val) return
    return dayjs(val).format('YYYY-MM-DD HH:mm:ss')
  },
  echartsTime: (val) => {
    if (!val) return
    return dayjs(val).format('MM/DD\n HH:mm:ss')
  },
  echartTime: (val) => {
    if (!val) return
    return dayjs(val).format('HH:mm:ss')
  },
  createTime: (val) => {
    if (!val) return
    return dayjs(val).format('YYYY-MM-DD HH:mm:ss')
  },
  chargeStartTime: (val) => {
    if (!val) return
    return dayjs(val).format('YYYY-MM-DD HH:mm:ss')
  },
  expireTime: (val) => {
    if (!val) return
    return dayjs(val).format('YYYY-MM-DD HH:mm:ss')
  },
  activeTime: (val) => {
    if (!val) return
    return dayjs(val).format('YYYY-MM-DD HH:mm:ss')
  },
  offlineTime: (val) => {
    if (!val) return
    return dayjs(val).format('YYYY-MM-DD HH:mm:ss')
  },
  changeDate: (val) => {
    if (!val) return
    return dayjs(val).format('YYYY-MM-DD HH:mm:ss')
  },
  licenseExpirationTime: (val) => {
    if (!val) return
    return dayjs(val).format('YYYY-MM-DD')
  },
  startDate: (val) => {
    if (!val) return
    return dayjs(val).format('YYYY-MM-DD')
  },
  endDate: (val) => {
    if (!val) return
    return dayjs(val).format('YYYY-MM-DD')
  },
  handleStatus: (val) => {
    return val ? '已处理' : '待处理'
  },
  resultStatus: (val) => {
    return val ? '成功' : '失败'
  },
  imei: (val) => {
    return val ? '已绑定' : '未绑定'
  },
  canHandle: (val) => {
    return val ? '可用' : '不可用'
  },
  // 向前补全0
  formatID: (val) => {
    return val.toString().padStart(5, '0')
  },
  fenceGroupList: (groupList) => {
    return groupList.map((item) => item.name).join(',')
  },
  inuse: (inuse) => {
    return inuse === 'TRUE' ? '已启用' : '未启用'
  },
  activeStatus: (activeStatus) => {
    return activeStatus ? '已激活' : '未激活'
  },
  allot: (allot) => {
    return allot ? '已分配' : '未分配'
  },
  alertTime: (val) => {
    if (!val) return
    return dayjs(val).format('YYYY-MM-DD HH:mm:ss')
  },
  cancelTime: (val) => {
    if (!val) return
    return dayjs(val).format('YYYY-MM-DD HH:mm:ss')
  },
  operateTime: (val) => {
    if (!val) return
    return dayjs(val).format('YYYY-MM-DD HH:mm:ss')
  },
  signTime: (val) => {
    if (!val) return
    return dayjs(val).format('HH:mm:ss')
  },
  operatorTime: (val) => {
    if (!val) return
    return dayjs(val).format('HH:mm:ss')
  },
  magnetismStatus: (magnetismStatus) => {
    return magnetismStatus ? '开启' : '关闭'
  },
  alarmTypes: (alarmTypes) => {
    return alarmTypes
      .map((alarmType) => {
        return typeMap.alarmType[alarmType]
      })
      .join(', ')
  },
  probes: (probes) => {
    return probes.join(', ')
  },
  alarmTemperature: (alarmTemperature) => {
    return alarmTemperature.join(', ')
  },
  extremeTemperature: (extremeTemperature) => {
    return extremeTemperature.join(', ')
  },
  applyTime: (val) => {
    if (!val) return
    return dayjs(val).format('YYYY-MM-DD HH:mm:ss')
  },
  requirePickTime: (val) => {
    if (!val) return
    return dayjs(val).format('YYYY-MM-DD HH:mm:ss')
  },
  alertTimes: (val) => {
    if (!val) return
    return formatTime(val)
  },
  operateTimes: (val) => {
    if (!val) return
    return formatTime(val)
  },
  wexinPay: (val) => {
    return val ? '已开通' : '未开通'
  },
  aliPay: (val) => {
    return val ? '已开通' : '未开通'
  },
  timeCardStatus: (status) => {
    return status ? '已绑定' : '待绑定'
  },

  splitType: (val) => {
    const splitType = {
      ALIPA_SPLIT: '支付宝',
      NOT_SPLIT: '不分账',
      WECHAT_SPLIT: '微信',
    }

    return splitType[val]
  },
}

// 方法重载
export default (...args) => {
  let key, value
  // Form format
  if (args.length === 2) {
    ;[key, value] = args
  } else {
    // Table format
    key = getPropByPath(args[0], args[1].property).k
    value = args[2]
  }

  if (!typeMap[key]) return
  if (typeof typeMap[key] === 'function') {
    return typeMap[key](value)
  } else {
    return typeMap[key][value] || value
  }
}
